<!DOCTYPE html>
<html>
<head>
    <meta name="viewport"
          content="width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1, maximum-scale=1"
          charset="utf-8"/>
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">

    <meta charset="UTF-8">
    <title>支付查询</title>
    <script type="text/javascript" src="jquery.js"></script>
</head>
<body>
<div style="float: left">
    <div>

    </div>
    <iframe id="model" name="model" src="index.html" height="540" width="337" scrolling="yes" allowtransparency="yes"
            frameBorder=1>
    </iframe>
    <br/>
    <a href="/">首页</a>
    <button class="qrcode" qrcodeType="1">就诊码</button>
    <button class="qrcode" qrcodeType="2">动态码</button>
    <button class="qrcode" qrcodeType="3">支付码</button>
</div>
<div style="float: left">
    <h1>支付查询</h1>
    <form id="payform">
        <table>
            <thead>
            <tr>
                <td>描述</td>
                <td>字段</td>
                <td>值</td>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td>账单时间</td>
                <td>bizCode</td>
                <td><input name="billDate" type="date"></td>
            </tr>
            </tbody>
        </table>
        <div>
            <button id="paybtn" type="button">点击提交</button>
            <a id="paydown" type="button" href="#">下载</a>
        </div>
        <div>
            结果展示 <textarea id="getinfotext" rows="5" cols="40"></textarea>
        </div>

    </form>
</div>


<script>
    $(function () {
        var H5 = JSON.parse(localStorage.getItem("config")).authHost+"/h5/";
        var accessToken = "accessToken=" + localStorage.getItem("accessToken")
        $("#model").attr("src", H5 + "personCenter?" + accessToken)
        $(".qrcode").click(function () {
            $("#model").attr("src", H5 + "qrcode?" + accessToken + "&qrcodeType=" + $(this).attr("qrcodeType"))
        });
        $("#paybtn").click(function () {
            var json = formmap("#payform");
            var url = "/bill"
            $.post(url,json,function (e) {
                $("#getinfotext").val(JSON.stringify(e))
                try {
                    $("#paydown").attr("href",e.rsp.billDownloadUrl);
                }catch (e) {
                    
                }
                
            })
        })
        $("#paydown").click(function () {
            if($(this).attr(href).indexOf("http")==-1){
                alert("请点击查询")
            }
        })

    })



    /**
     * form转换为json
     * @param dom
     */
    function formmap(dom) {
        var o = {};
        var a = $(dom).serializeArray();
        $.each(a, function () {
            if (o[this.name]) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                if(this.value){
                    o[this.name].push(this.value);
                }
            } else {
                if(this.value) {
                    o[this.name] = this.value || '';
                }
            }
        });
        return o;
    }
</script>
</body>
</html>